# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="yangqibin"
__date__ ="$Nov 12, 2011 7:58:50 PM$"

import web, datetime
import res_code


db = web.database(dbn='mysql', db='blog', user='yangqibin', passwd='yangqibin')

def get_posts():
    return db.select('entries', order='id DESC')

def get_post(id):
    try:
        return db.select('entries', where="id=$id", vars=locals())[0]
    except IndexError:
        return None

def new_post(title, content):
    db.insert('entries', title=title, content=content, posted_on=datetime.datetime.utcnow())

def del_post(id):
    db.delete('entries', where="id=$id", vars=locals())

def update_post(id, title, text):
    db.update('entries', where="id=$id", vars=locals(), title=title, content=text)



if __name__ == "__main__":
    print "Hello World"
